Telegram Group & Telegram Channel
⛄️ Как использовать std::span для безопасного доступа к последовательностям данных

Устали от споров «что лучше передать: вектор, массив или указатель с длиной»? C++20 предлагает элегантное решение!

#include <span>
#include <vector>
#include <array>

// Функция работает с ЛЮБЫМ непрерывным контейнером!
void processData(std::span<const int> data) {
for (const auto& item : data) {
// Обработка
}
}

int main() {
// Работает с std::vector
std::vector<int> vec = {1, 2, 3, 4, 5};
processData(vec);

// Работает с std::array
std::array<int, 3> arr = {10, 20, 30};
processData(arr);

// Работает с C-массивами
int classic[] = {100, 200, 300};
processData(classic);

// Работает с подпоследовательностями!
processData(std::span(vec).subspan(1, 3)); // Только элементы 2,3,4
}


❗️Преимущества std::span:

- Не владеет данными (zero overhead)
- Безопасно передает подпоследовательности
- Унифицированный интерфейс для всех контейнеров
- Выразительный код без шаблонных параметров

Библиотека C/C++ разработчика #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/cppproglib/5689
Create:
Last Update:

⛄️ Как использовать std::span для безопасного доступа к последовательностям данных

Устали от споров «что лучше передать: вектор, массив или указатель с длиной»? C++20 предлагает элегантное решение!

#include <span>
#include <vector>
#include <array>

// Функция работает с ЛЮБЫМ непрерывным контейнером!
void processData(std::span<const int> data) {
for (const auto& item : data) {
// Обработка
}
}

int main() {
// Работает с std::vector
std::vector<int> vec = {1, 2, 3, 4, 5};
processData(vec);

// Работает с std::array
std::array<int, 3> arr = {10, 20, 30};
processData(arr);

// Работает с C-массивами
int classic[] = {100, 200, 300};
processData(classic);

// Работает с подпоследовательностями!
processData(std::span(vec).subspan(1, 3)); // Только элементы 2,3,4
}


❗️Преимущества std::span:

- Не владеет данными (zero overhead)
- Безопасно передает подпоследовательности
- Унифицированный интерфейс для всех контейнеров
- Выразительный код без шаблонных параметров

Библиотека C/C++ разработчика #буст

BY Библиотека C/C++ разработчика | cpp, boost, qt


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/cppproglib/5689

View MORE
Open in Telegram


Библиотека C C разработчика | cpp boost qt Telegram | DID YOU KNOW?

Date: |

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

How to Invest in Bitcoin?

Like a stock, you can buy and hold Bitcoin as an investment. You can even now do so in special retirement accounts called Bitcoin IRAs. No matter where you choose to hold your Bitcoin, people’s philosophies on how to invest it vary: Some buy and hold long term, some buy and aim to sell after a price rally, and others bet on its price decreasing. Bitcoin’s price over time has experienced big price swings, going as low as $5,165 and as high as $28,990 in 2020 alone. “I think in some places, people might be using Bitcoin to pay for things, but the truth is that it’s an asset that looks like it’s going to be increasing in value relatively quickly for some time,” Marquez says. “So why would you sell something that’s going to be worth so much more next year than it is today? The majority of people that hold it are long-term investors.”

Библиотека C C разработчика | cpp boost qt from br


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM USA